
<font color="#112233">
<?php
################################################################################   
## +---------------------------------------------------------------------------+
## | 1. Creating & Calling:                                                    | 
## +---------------------------------------------------------------------------+
##  *** only relative (virtual) path (to the current document)
  define ("DATAGRID_DIR", "../datagrid/");
  define ("PEAR_DIR", "../datagrid/pear/");
  define ("MODEL_DIR", "../model/");
  
  require_once(DATAGRID_DIR.'datagrid.class.php');
  require_once(PEAR_DIR.'PEAR.php');
  require_once(PEAR_DIR.'DB.php');
  require_once(MODEL_DIR.'config.inc');   

##  *** creating variables that we need for database connection 
    

ob_start();
    $db_conn = DB::factory('mysql'); 
    $db_conn -> connect(DB::parseDSN('mysql://'.$db_user.':'.$db_pass.'@'.$hostname.'/'.$db_name));
	//$db_conn = new DBBase();
	//$db_conn->connect();
	
 

##  *** put a primary key on the first place 
  $sql=" SELECT "  
   ."tblproduct.pro_id, "
   ."tblproduct.pro_name, "
   ."tblproduct.pro_desc, "
   ."tblproduct.pro_prince, "
   ."tblproduct.price_bid, "
   ."tblproduct.country_id, "
   ."tblproduct.pro_image1, "
   ."tblproduct.pro_image2, "
   ."tblproduct.pro_image3, "
   ."tblproduct.pro_image4, "
   ."tblproduct.pro_image5, "
   ."tblproduct.categories_id, "
   ." CASE WHEN tblproduct.status = 1 THEN 'Bidding' ELSE 'Sold' END as status "
   ."FROM tblproduct ";
##  *** set needed options
  $debug_mode = false;
  $messaging = true;
  $unique_prefix = "f_";  
  
  $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
##  *** set data source with needed options
  $default_order_field = "pro_id";
  $default_order_type = "ASC";
  $dg_encoding = "utf8";
  $dg_collation = "utf8_unicode_ci";
  $dgrid->SetEncoding($dg_encoding, $dg_collation);
  $dgrid->dataSource($db_conn, $sql, $default_order_field, $default_order_type);	 
  $http_get_vars = array("page");
  $dgrid->SetHttpGetVars($http_get_vars); 
  $css_class = "blue";
  $dgrid->SetCssClass($css_class);
##  *** set paging option: true(default) or false 
  $paging_option = true;
  $rows_numeration = false;
  $numeration_sign = "N #";
  $dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign);
##  *** set paging settings
  $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  $top_paging = array();
  $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  $default_page_size = 20;
  $paging_arrows = array("first"=>"|&lt;&lt;", "previous"=>"&lt;&lt;", "next"=>"&gt;&gt;", "last"=>"&gt;&gt;|");
  $dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);
##  *** set DataGrid caption
  $dg_caption = "Product List";
  $dgrid->SetCaption($dg_caption);  

## +---------------------------------------------------------------------------+
## | 6. View Mode Settings:                                                    | 
## +---------------------------------------------------------------------------+
##  *** set columns in view mode
//   $dgrid->setAutoColumnsInViewMode(true);  
 $vm_colimns = array(
    "pro_name"  =>array("header"=>"Product Name",      "type"=>"linktoedit", "width"=>"130px", "align"=>"left",   "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "pro_prince"   =>array("header"=>"Product price",       "type"=>"label", "summarize"=>false, "align"=>"right",  "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
    "price_bid"  =>array("header"=>"Price Bid","type"=>"label", "align"=>"left",   "wrap"=>"wrap",   "text_length"=>"30", "case"=>"lower"),
	"status"  =>array("header"=>"Status","type"=>"label", "align"=>"left",   "wrap"=>"wrap",   "text_length"=>"30", "case"=>"lower"),
	"country_id"  =>array("header"=>"Country","type"=>"label", "align"=>"left",   "wrap"=>"wrap",   "text_length"=>"30", "case"=>"lower"),
    "pro_image1"  =>array("header"=>"Image",          "type"=>"image", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal", "summarize"=>false, "on_js_event"=>"", "target_path"=>"../images-products/", "default"=>"", "image_width"=>"110px", "image_height"=>"110px"),
  );
  $dgrid->setColumnsInViewMode($vm_colimns);


## +---------------------------------------------------------------------------+
## | 7. Add/Edit/Details Mode settings:                                        | 
## +---------------------------------------------------------------------------+
##  ***  set settings for edit/details mode
  $table_name = "tblproduct";
  $primary_key = "pro_id";
  $condition = "";
  $dgrid->setTableEdit($table_name, $primary_key, $condition);
//  $dgrid->setAutoColumnsInEditMode(true);
##  *** set columns in edit mode
##  *** first letter: r - required, s - simple (not required)
##  *** second letter: t - text(including datetime), n - numeric, a - alphanumeric, e - email, f - float, y - any, l - login name, z - zipcode, p - password, i - integer, v - verified
##  *** third letter (optional): 
##          for numbers: s - signed, u - unsigned, p - positive, n - negative
##          for strings: u - upper,  l - lower,    n - normal,   y - any
##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
##  *** Ex.: type = textbox|textarea|label|date(yyyy-mm-dd)|datedmy(dd-mm-yyyy)|datetime(yyyy-mm-dd hh:mm:ss)|datetimedmy(dd-mm-yyyy hh:mm:ss)|image|password|enum|print|checkbox
##  *** make sure your WYSIWYG dir has 755 permissions
  $em_columns = array(
    "pro_name"        =>array("header"=>"Product Name",           "type"=>"textbox",  "width"=>"210px", "req_type"=>"", "title"=>"Product Name"),
	"categories_id" =>array("header"=>"Category", "type"=>"textbox",  "width"=>"210px", "req_type"=>"rt", "title"=>"Category"),
    "pro_desc"      =>array("header"=>"Product Description",     "type"=>"textarea", "width"=>"210px", "req_type"=>"", "title"=>"Product Description", "edit_type"=>"wysiwyg", "rows"=>"7", "cols"=>"50"),
    "pro_prince"       =>array("header"=>"Product price",          "type"=>"textbox",  "width"=>"210px", "req_type"=>"rt", "title"=>"Product price"),
	"country_id"     =>array("header"=>"Country",     "type"=>"textbox",  "width"=>"210px", "req_type"=>"rt", "title"=>"Country"),
    "pro_image1"      =>array("header"=>"Image1 URL",        "type"=>"image",    "req_type"=>"st", "width"=>"210px", "title"=>"Picture", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "on_js_event"=>"", "target_path"=>"../images-products/", "max_file_size"=>"1020K", "image_width"=>"100px", "image_height"=>"100px", "file_name"=>"", "host"=>"local"),
    "pro_image2"      =>array("header"=>"Image2 URL",        "type"=>"image",    "req_type"=>"st", "width"=>"210px", "title"=>"Picture", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "on_js_event"=>"", "target_path"=>"../images-products/", "max_file_size"=>"1020K", "image_width"=>"100px", "image_height"=>"100px", "file_name"=>"", "host"=>"local"),
	"pro_image3"      =>array("header"=>"Image3 URL",        "type"=>"image",    "req_type"=>"st", "width"=>"210px", "title"=>"Picture", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "on_js_event"=>"", "target_path"=>"../images-products/", "max_file_size"=>"1020K", "image_width"=>"100px", "image_height"=>"100px", "file_name"=>"", "host"=>"local"),
	"pro_image4"      =>array("header"=>"Image4 URL",        "type"=>"image",    "req_type"=>"st", "width"=>"210px", "title"=>"Picture", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "on_js_event"=>"", "target_path"=>"../images-products/", "max_file_size"=>"1020K", "image_width"=>"100px", "image_height"=>"100px", "file_name"=>"", "host"=>"local"),
	"pro_image5"      =>array("header"=>"Image5 URL",        "type"=>"image",    "req_type"=>"st", "width"=>"210px", "title"=>"Picture", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "on_js_event"=>"", "target_path"=>"../images-products/", "max_file_size"=>"1020K", "image_width"=>"100px", "image_height"=>"100px", "file_name"=>"", "host"=>"local"),
    "status"     =>array("header"=>"Status",     "type"=>"checkbox", "true_value"=>1, "false_value"=>0,  "width"=>"210px", "req_type"=>"sy", "title"=>"Status"),
    "price_bid" =>array("header"=>"Price Bid", "type"=>"textbox",  "width"=>"210px", "req_type"=>"rt", "title"=>"Price Bid")
  );
  $dgrid->setColumnsInEditMode($em_columns);
  
##  *** set foreign keys for add/edit/details modes (if there are linked tables)
##  *** Ex.: "condition"=>"TableName_1.FieldName > 'a' AND TableName_1.FieldName < 'c'"
##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
 $foreign_keys = array(
    "categories_id"=>array("table"=>"tblcategories", "field_key"=>"categories_id", "field_name"=>"categories_name", "view_type"=>"dropdownlist", "order_by_field"=>"categories_name", "order_type"=>"ASC"),
	"country_id"=>array("table"=>"tblcountry", "field_key"=>"country_id", "field_name"=>"country_name", "view_type"=>"dropdownlist", "order_by_field"=>"country_name", "order_type"=>"ASC")
 ); 
 $dgrid->setForeignKeysEdit($foreign_keys);
## +---------------------------------------------------------------------------+
## | 8. Bind the DataGrid:                                                     | 
## +---------------------------------------------------------------------------+
##  *** set debug mode & messaging options
    $dgrid->bind();        
    ob_end_flush();
################################################################################   
?>
